﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.Mobile.ContainerModel;
using EventAggregationQuickStart;
using Microsoft.Practices.Composite.Events;

namespace ModuleA
{
    public class ModuleAConfigurator : IContainerModule
    {
		ITaskService tasks;

        public ModuleAConfigurator(ITaskService tasks)
		{
			this.tasks = tasks;
		}

        #region IContainerModule Members

        public void Configure(Container container)
        {
            // Register the presenter and view types.
            RegisterTypes(container);

            // Register the launch tasks for the main screen.
            RegisterTasks(container);
        }

        #endregion

        private void RegisterTasks(Container container)
        {
            // This is the entry point to our module.
            tasks.Register<ModuleAPresenter>("FirstView");
        }

        private void RegisterTypes(Container container)
        {
            // Register the View. The InitializedBy function here asks the container to
            // resolve the ManageUsersPresenter (i.e. create one if we haven't got one)
            // and set the views' Presenter property to that instance.
            container
                .Register<IModuleAView>(
                    c => new ModuleAView())
                .InitializedBy(
                    (c, v) => v.Presenter = c.Resolve<ModuleAPresenter>());

            // Register the factory function for the Presenter.
            container.Register(c => new ModuleAPresenter(
                    c.Resolve<IModuleAView>(),
                    c.Resolve<IRegionManagerService>(),
                    c.Resolve<IEventAggregator>()));
        }
    }
}
